<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/27 0027
 * Time: 01:51
 */
$res = preg_replace('/\[link\ url="([^"]+)"\](.*?)\[\/link\]/', '<a href="\\1">\\2</a>', '[link url="http://www.baidu/com"]百度[/link] is ok');
//var_dump($res);//"<a href="http://www.baidu/com">百度</a> is ok"

$string = '这个字符串中的php和mysql被替换成大写的了！';

//$result = preg_replace('/(php)|(mysql)/e','strtoupper("${1}\2")',$string,-1,$count);
//$result = preg_replace('/(php)|(mysql)/e', 'strtoupper("\\1 \\2")', $string, -1, $count);
//echo $result;

$arr = [
    'a ,b',
    'b ,c',
    'd ,f'
];
function ucwordss($arr)
{
    var_dump($arr);
//    return $var2 . ',' . $var1;
}

$result = preg_replace('@([^,]+).\ (.*)@', 'ucwordss', $arr);

//$a = preg_replace("/([A-Z])/",'gwyy', 'asdasdasAA');
////var_dump($a);
//function gwyy($match){
//    var_dump($match);
////    return  '_'.strtolower($match[1]);
//}

$result = preg_replace_callback('/([A-Z])/',
    function ($matches) {
        return '_' . strtolower($matches[0]);
    },
    'Abc');
var_dump($result);


//var_dump($result);
$string = 'google 123, 456';
$pattern = '/(\w+) (\d+), (\d+)/i';
$replacement = 'runoob ${2},$3';
//echo preg_replace($pattern, $replacement, $string); //runoob 123,456

$string = 'The quick brown fox jumped over the lazy dog.';
$patterns = array();
$patterns[0] = '/quick/';
$patterns[1] = '/brown/';
$patterns[2] = '/fox/';
$replacements = array();
$replacements[2] = 'bear';
$replacements[1] = 'black';
$replacements[0] = 'slow';
//echo preg_replace($patterns, $replacements, $string); //The bear black slow jumped over the lazy dog.

//https://www.cnblogs.com/crxis/p/7714636.html
//https://www.baidu.com/link?url=5VjpdUkLG1fB-448VgZY4y-Zer-vE7y97azJeWQ_-HX5umeaA3T-Um9B9z_2SpnCZvwnm3BLGb60G6-ya2xwufXJsUPrfgYlwF5ndBoSTuS&wd=&eqid=838967a200045b84000000035c9ce7e2